Return to doc.sitecore.com

Valid for Sitecore 5.2, 5.1.1
  Add the GetTemplates Method
Prev Next

Since the Hello World data provider only returns a single item with a single field, it only needs to provide a single Template that describes the field.  In this example, we create the template programmatically in the GetTemplates method. 

Create the method using the source code shown below.

1.  GetTemplates

1 public override TemplateCollection GetTemplates(CallContext context)
2 {
3
4   Assert.ArgumentNotNull(context, "context");
5   Template[] templateArray = new Template[1];
6   ID templateId = this.TemplateId;
7   ID newID = ID.NewID;
8   ID titleId = this.TitleId;
9
10   // We need to return a template collection, and we
11   // pass it as the owner of all templates in the template builder
12   TemplateCollection owner = new TemplateCollection();
13
14   // Create the template
15   Template.Builder builder = new Template.Builder("Hello World Template",
16                                                    templateID, owner);
17   builder.SetFullName("Hello World Template");
18   builder.SetIcon("/sitecore/shell/themes/standard/Network/16x16/earth2.png");
19   builder.SetBaseIDs(string.Empty);
20
21   // Create a Data section
22   TemplateSection.Builder builder2 = builder.AddSection("Data",newID);
23   builder2.SetIcon("Network/16x16/earth2.png");
24
25   // Create a Title field
26   TemplateField.Builder builder3 = builder2.AddField("Title",titleID);
27   builder3.SetIcon(string.Empty);
28   builder3.SetShared(false);
29   builder3.SetSortorder(0);
30   builder3.SetStyle(string.Empty);
31   builder3.SetType("text");
32   builder3.SetUnversioned(false);
33
34   templateArray[0] = builder.Template;
35   owner.Reset(templatesArray);
36
37   // Return the template collection which contains our template
38   return owner;
39
40 }

Prev Next